<?php

class Game_List_Model extends CI_Model {

        private $GAMESET_TABLE = 'game_sets';

		// Get all ongoing game sets (challenges in progress)
        function get_ongoing_games() {
               	$select_games = array(0 => 'game_set_id', 1 => 'player1', 2 => 'player2', 3 => 'player1_wins', 4 => 'player2_wins');
                $this->db->select($select_games);
                $this->db->where('status', 'ongoing');
                
                $query = $this->db->get($this->GAMESET_TABLE);
                $rows = $query->result_array();

                return $rows;
        }

        
        // Get all recently completed game sets
        function get_recent_games() {
               	$select_games = array(0 => 'game_set_id', 1 => 'player1', 2 => 'player2', 3 => 'player1_wins', 4 => 'player2_wins');
                $this->db->select($select_games);
                $this->db->where('status', 'finished');                       // Comment out for testing while there are no finished game sets

                // ALSO add some code to only fetch, say, 10 most recent game sets completed
                
                $query = $this->db->get($this->GAMESET_TABLE);
                $rows = $query->result_array();

                return $rows;
        }
        
}

?>

